import math


def calculate_ppi(width:int, height:int, screen_size: int) -> int:
    """【函数】已知分辨率与屏幕尺寸，求像素密度（PPI）"""
    ppi = int(math.sqrt(width ** 2 +  height ** 2) / screen_size)
    return ppi


def calculate_resolution(ppi: int, screen_size: int, ratio: float) -> tuple:
    """【函数】已知像素密度（PPI）与屏幕尺寸，求分辨率"""
    height = int((ppi * screen_size) / (math.sqrt(1+ratio**2)))
    width = int(height * ratio)
    return (width, height)



if (__name__ == "__main__"):

    width_surface = 2736
    height_surface = 1824
    size_surface = 12    # 屏幕尺寸

    ppi_surface = calculate_ppi(width_surface, height_surface, size_surface)
    print("Surface Pro 6 的像素密度（PPI）为:", ppi_surface, "PPI")

    ratio = 16/10     # 屏幕比例
    h = 0
    w = 0
    size_target = 16    # 屏幕尺寸

    (w, h) = calculate_resolution(ppi_surface, size_target, ratio)
    print("16寸同等像素密度的分辨率（Resolution）为:", w, "*", h, "Pixel")
    
    ppi_yoga16s = calculate_ppi(2560, 1600, 16)
    print("Lenovo Yoga 16s 的像素密度为:", ppi_yoga16s, "PPI")

    ppi_yoga14 = calculate_ppi(2880, 1800, 14)
    print("Lenovo Yoga 14 的像素密度为:", ppi_yoga14, "PPI")

    ppi_p40pro = calculate_ppi(2640, 1200, 6.58)
    print("HUAWEI P40 Pro 的像素密度为:", ppi_p40pro,"PPI")
